package com.lagou.demo;

//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
import com.lagou.mapper.UserMapper;
import com.lagou.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MyBatisPluginTest {

    private UserMapper userMapper;
    private SqlSession sqlSession;

    @Before
    public void before() throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream);
        sqlSession = build.openSession();
        userMapper = sqlSession.getMapper(UserMapper.class);
    }

    @After
    public void after() {
        sqlSession.close();
    }

    @Test
    public void myPlugin() {
        List<User> users = userMapper.findAll();
        users.forEach(user -> System.out.println(user));
    }

    @Test
    public void pageHelper() {
//        PageHelper.startPage(1,2);
        List<User> users = userMapper.findAll();
        users.forEach(user -> System.out.println(user));
//        PageInfo<User> pageInfo = new PageInfo<>(users);
//        System.out.println(pageInfo);
    }


}
